<html>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<body>

<script>
description('This test checks the behavior of DOM operations when called on non-DOM or incompatible receivers with non-DOM or incompatible arguments.');

function trySuspect(fun) {
  try {
    result = fun();
    return '' + result;
  } catch (e) {
    return 'threw ' + e;
  }
}

function check(a, b) {
  return 1;
}

var aDOMImplementation = document.implementation;

var aSelect = document.createElement("select");
var anOption = document.createElement("option");
var aNode = document.createElement("div");
var aSecondNode = document.createElement("div");
aNode.appendChild(aSecondNode);

shouldThrow("aNode.appendChild(aDOMImplementation)", '"TypeError: Failed to execute \'appendChild\' on \'Node\': parameter 1 is not of type \'Node\'."');

shouldThrow("aNode.appendChild('knort')", '"TypeError: Failed to execute \'appendChild\' on \'Node\': parameter 1 is not of type \'Node\'."');

shouldThrow("aNode.appendChild(void 0)", '"TypeError: Failed to execute \'appendChild\' on \'Node\': parameter 1 is not of type \'Node\'."');

shouldThrow("aNode.isSameNode(aDOMImplementation)");
shouldThrow("aNode.isSameNode('foo')");
shouldBeFalse("aNode.isSameNode(void 0)");
shouldBe("aNode.lookupPrefix(aDOMImplementation)", "null");
shouldBe("aNode.lookupPrefix(void 0)", "null");
shouldBeTrue("aNode.cloneNode(aDOMImplementation) instanceof HTMLDivElement");
shouldThrow("aSelect.add(aDOMImplementation, aDOMImplementation)");
shouldThrow("aSelect.add(aDOMImplementation, anOption)");
shouldThrow("aSelect.add(void 0, void 0)");
shouldThrow("aSelect.add(void 0, anOption)");
shouldBeUndefined("aSelect.add(anOption, aDOMImplementation)");
shouldBeUndefined("aSelect.add(anOption, void 0)");
</script>
</body>
</html>

